package com.boho.ecp.cart.action;

import java.sql.Connection;

import cn.boho.framework.actions.ActionImp;
import cn.boho.framework.context.ActionContext;
import cn.boho.framework.service.MessageService;

import com.boho.ecp.cart.service.CartService;
import com.boho.ecp.product.service.ProductService;

public class AddProductToCartAction extends ActionImp {

	private Integer productId;
	private Integer qty;
	
	@Override
	protected void doException(ActionContext atx, Exception ex) {
		atx.setErrorContext("ADD_PRODUCT_FAIL", MessageService.getMessage("ADD_PRODUCT_FAIL"), ex);
	}

	@Override
	protected int performExecute(ActionContext atx) throws Exception {
		Connection con = atx.getConection();
		CartService.saveCart(atx, con, productId, qty);
		CartService.queryCart(atx, con);
		ProductService.updateMindByProductId(con, productId);
		return 1;
	}

	@Override
	protected int verifyParameters(ActionContext atx) throws Exception {
		productId = atx.getIntegerValue("PRODUCT_ID");
		qty = atx.getIntegerValue("QTY", 1);
		return 1;
	}
}
